home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 March / PCWorld_2001-03_cd.bin / Software / TemaCD / classbuild / ClassBuilder 2.2 PR405 Setup.exe / {app} / Include / CB_CriticalValueTree.h < prev    next >
C/C++ Source or Header  |  2000-04-06  |  13KB  |  347 lines

  1. #ifndef CB_CRITICAL_VALUETREE_H
  2. #define CB_CRITICAL_VALUETREE_H
  3.  
  4. #include <assert.h>
  5.  
  6. #include "CB_CriticalSection.h"
  7. #include "CB_ValueTree.h"
  8.  
  9. // defines for include files
  10. #define RELATION_TEMPLATE_CRITICAL_VALUETREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  11. private:\
  12.     ClassTo* _first##NameTo;\
  13.     int _count##NameTo;\
  14. \
  15. public:\
  16.     static CriticalSection& CriticalSection##NameTo()\
  17.     {\
  18.         static CriticalSection criticalSection##NameTo;\
  19.         return criticalSection##NameTo;\
  20.     }\
  21. \
  22.     void Add##NameTo(ClassTo* item)\
  23.     {\
  24.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  25.         METHOD_VALUETREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  26.     }\
  27.     void Remove##NameTo(ClassTo* item)\
  28.     {\
  29.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  30.         METHOD_VALUETREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  31.     }\
  32.     void RemoveAll##NameTo()\
  33.     {\
  34.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  35.         METHOD_VALUETREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  36.     }\
  37.     void DeleteAll##NameTo()\
  38.     {\
  39.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  40.         METHOD_VALUETREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  41.     }\
  42.     void Replace##NameTo(ClassTo* item, ClassTo* newItem)\
  43.     {\
  44.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  45.         METHOD_VALUETREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  46.     }\
  47.     ClassTo* GetFirst##NameTo() const\
  48.     {\
  49.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  50.         METHOD_VALUETREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
  51.     }\
  52.     ClassTo* GetLast##NameTo() const\
  53.     {\
  54.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  55.         METHOD_VALUETREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
  56.     }\
  57.     ClassTo* GetNext##NameTo(ClassTo* pos) const\
  58.     {\
  59.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  60.         METHOD_VALUETREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
  61.     }\
  62.     ClassTo* GetPrev##NameTo(ClassTo* pos) const\
  63.     {\
  64.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  65.         METHOD_VALUETREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
  66.     }\
  67.     int Get##NameTo##Count() const\
  68.     {\
  69.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  70.         METHOD_VALUETREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
  71.     }\
  72.     ITERATOR_TEMPLATE_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
  73.  
  74. #define RELATION_TEMPLATE_NOFILTER_CRITICAL_VALUETREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  75. private:\
  76.     ClassTo* _first##NameTo;\
  77.     int _count##NameTo;\
  78. \
  79. public:\
  80.     static CriticalSection& CriticalSection##NameTo()\
  81.     {\
  82.         static CriticalSection criticalSection##NameTo;\
  83.         return criticalSection##NameTo;\
  84.     }\
  85. \
  86.     void Add##NameTo(ClassTo* item)\
  87.     {\
  88.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  89.         METHOD_VALUETREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  90.     }\
  91.     void Remove##NameTo(ClassTo* item)\
  92.     {\
  93.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  94.         METHOD_VALUETREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  95.     }\
  96.     void RemoveAll##NameTo()\
  97.     {\
  98.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  99.         METHOD_VALUETREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  100.     }\
  101.     void DeleteAll##NameTo()\
  102.     {\
  103.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  104.         METHOD_VALUETREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  105.     }\
  106.     void Replace##NameTo(ClassTo* item, ClassTo* newItem)\
  107.     {\
  108.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  109.         METHOD_VALUETREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  110.     }\
  111.     ClassTo* GetFirst##NameTo() const\
  112.     {\
  113.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  114.         METHOD_VALUETREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
  115.     }\
  116.     ClassTo* GetLast##NameTo() const\
  117.     {\
  118.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  119.         METHOD_VALUETREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
  120.     }\
  121.     ClassTo* GetNext##NameTo(ClassTo* pos) const\
  122.     {\
  123.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  124.         METHOD_VALUETREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
  125.     }\
  126.     ClassTo* GetPrev##NameTo(ClassTo* pos) const\
  127.     {\
  128.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  129.         METHOD_VALUETREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
  130.     }\
  131.     int Get##NameTo##Count() const\
  132.     {\
  133.         CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  134.         METHOD_VALUETREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
  135.     }\
  136.     ITERATOR_TEMPLATE_NOFILTER_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
  137.  
  138. #define RELATION_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  139. private:\
  140.     ClassTo* _first##NameTo;\
  141.     int _count##NameTo;\
  142. \
  143. public:\
  144.     static CriticalSection _criticalSection##NameTo;\
  145.     static CriticalSection& CriticalSection##NameTo() { return _criticalSection##NameTo; }\
  146. \
  147.     void Add##NameTo(ClassTo* item);\
  148.     void Remove##NameTo(ClassTo* item);\
  149.     void RemoveAll##NameTo();\
  150.     void DeleteAll##NameTo();\
  151.     void Replace##NameTo(ClassTo* item, ClassTo* newItem);\
  152.     ClassTo* GetFirst##NameTo() const;\
  153.     ClassTo* GetLast##NameTo() const;\
  154.     ClassTo* GetNext##NameTo(ClassTo* pos) const;\
  155.     ClassTo* GetPrev##NameTo(ClassTo* pos) const;\
  156.     int Get##NameTo##Count() const;\
  157.     ITERATOR_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
  158.  
  159. #define RELATION_NOFILTER_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  160. private:\
  161.     ClassTo* _first##NameTo;\
  162.     int _count##NameTo;\
  163. \
  164. public:\
  165.     static CriticalSection _criticalSection##NameTo;\
  166.     static CriticalSection& CriticalSection##NameTo() { return _criticalSection##NameTo; }\
  167. \
  168.     void Add##NameTo(ClassTo* item);\
  169.     void Remove##NameTo(ClassTo* item);\
  170.     void RemoveAll##NameTo();\
  171.     void DeleteAll##NameTo();\
  172.     void Replace##NameTo(ClassTo* item, ClassTo* newItem);\
  173.     ClassTo* GetFirst##NameTo() const;\
  174.     ClassTo* GetLast##NameTo() const;\
  175.     ClassTo* GetNext##NameTo(ClassTo* pos) const;\
  176.     ClassTo* GetPrev##NameTo(ClassTo* pos) const;\
  177.     int Get##NameTo##Count() const;\
  178.     ITERATOR_NOFILTER_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
  179.  
  180. #define RELATION_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  181. public:\
  182.     ClassFrom* _ref##NameFrom;\
  183.     ClassTo* _parent##NameFrom;\
  184.     ClassTo* _left##NameFrom;\
  185.     ClassTo* _right##NameFrom;\
  186.     ClassTo* _sibling##NameFrom;\
  187. \
  188. public:\
  189.     ClassFrom* Get##NameFrom() const { return _ref##NameFrom; };
  190.  
  191. // defines implementation
  192. #define INIT_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  193. {\
  194.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  195.     INIT_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  196. }
  197.  
  198. #define EXIT_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  199. {\
  200.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  201.     EXIT_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  202. }
  203.  
  204. #define REPLACE_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  205. {\
  206.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  207.     REPLACE_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  208. }
  209.  
  210. #define INIT_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  211. {\
  212.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  213.     INIT_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  214. }
  215.  
  216. #define EXIT_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  217. {\
  218.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  219.     EXIT_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  220. }
  221.  
  222. #define REPLACE_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  223. {\
  224.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  225.     REPLACE_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  226. }
  227.  
  228. #define REMOVE_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  229. {\
  230.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  231.     REMOVE_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  232. }
  233.  
  234. #define SAVE_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  235. {\
  236.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  237.     SAVE_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  238. }
  239.  
  240. #define RESTORE_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  241. {\
  242.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  243.     RESTORE_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  244. }
  245.  
  246. #define REMOVE_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  247. {\
  248.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  249.     REMOVE_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  250. }
  251.  
  252. #define CLEANUP_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  253. {\
  254.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  255.     CLEANUP_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  256. }
  257.  
  258. #define METHODS_CRITICAL_VALUETREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  259.     CriticalSection ClassFrom##::_criticalSection##NameTo;\
  260. void ClassFrom##::Add##NameTo(ClassTo* item)\
  261. {\
  262.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  263.     METHOD_VALUETREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  264. }\
  265. \
  266. void ClassFrom##::Remove##NameTo(ClassTo* item)\
  267. {\
  268.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  269.     METHOD_VALUETREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  270. }\
  271. \
  272. void ClassFrom##::RemoveAll##NameTo()\
  273. {\
  274.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  275.     METHOD_VALUETREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  276. }\
  277. \
  278. void ClassFrom##::DeleteAll##NameTo()\
  279. {\
  280.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  281.     METHOD_VALUETREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
  282. }\
  283. \
  284. void ClassFrom##::Replace##NameTo(ClassTo* item, ClassTo* newItem)\
  285. {\
  286.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  287.     METHOD_VALUETREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
  288. }\
  289. \
  290. ClassTo* ClassFrom##::GetFirst##NameTo() const\
  291. {\
  292.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  293.     METHOD_VALUETREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
  294. }\
  295. \
  296. ClassTo* ClassFrom##::GetLast##NameTo() const\
  297. {\
  298.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  299.     METHOD_VALUETREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
  300. }\
  301. \
  302. ClassTo* ClassFrom##::GetNext##NameTo(ClassTo* pos) const\
  303. {\
  304.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  305.     METHOD_VALUETREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
  306. }\
  307. \
  308. ClassTo* ClassFrom##::GetPrev##NameTo(ClassTo* pos) const\
  309. {\
  310.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  311.     METHOD_VALUETREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
  312. }\
  313. \
  314. int ClassFrom##::Get##NameTo##Count() const\
  315. {\
  316.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  317.     METHOD_VALUETREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
  318. }
  319.  
  320. #define METHODS_CRITICAL_VALUETREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo)
  321.  
  322. #define BODY_CRITICAL_VALUETREE_FIND(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
  323. {\
  324.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  325.     BODY_VALUETREE_FIND(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
  326. }
  327.  
  328. #define BODY_CRITICAL_VALUETREE_FINDREVERSE(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
  329. {\
  330.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  331.     BODY_VALUETREE_FINDREVERSE(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
  332. }
  333.  
  334. #define WRITE_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  335. {\
  336.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  337.     WRITE_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  338. }
  339.  
  340. #define READ_CRITICAL_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  341. {\
  342.     CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
  343.     READ_VALUETREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
  344. }
  345.  
  346. #endif
  347.